#if SDP_CLIENT

#ifndef SDP_STATE_MACHINE_H
#define SDP_STATE_MACHINE_H

#include "host_config.h"

#include "sdp_stack_access.h"

#include "sdp_constants.h"
#include "sdp_ue.h"

struct rdabt_sdp_primitive_task;

typedef void (*rdabt_sdp_task_function)(struct rdabt_sdp_primitive_task* p_primitive, u_int32 length, u_int8* p_data, u_int8* pContinue);

typedef void (*rdabt_sdp_task_main)(struct rdabt_sdp_primitive_task* p_primitive, u_int8* pContinue);


struct rdabt_sdp_task
{
  u_int16 transaction_id;
  u_int8 expects;
  u_int16 state;

  rdabt_sdp_task_main execute;
  rdabt_sdp_task_function waiter;
};



struct rdabt_sdp_primitive_task
{
  u_int32 service_primitive_id;
  /*   u_int16 application_id; */
  u_int8 timer_handle;

    u_int16 mtu;

  u_int32 length;
  u_int8* rx_buffer;
  u_int32 rx_size;
  u_int32 offset;
  u_int32 current_bd;
  u_int8 status;
  u_int8 keep_connection;
  u_int8 w4_l2cap_connection;
  u_int8 w4_name;
  u_int8 w4_Service_Search;
  u_int8 record_handles_left;
  u_int8 sequence_type;
  u_int32* service_records;
  t_bdaddr address; 

  t_SDP_SearchPattern pattern; 
  t_SDP_AttributeIDs attributes;
  t_SDP_StopRule rule;  
  
  t_channelId cid;
  
  u_int8 module_id;
  t_SDP_Results* app_data;
    
  rdabt_sdp_task_function execute;
  
  struct rdabt_sdp_task sub_task_level_1;
  struct rdabt_sdp_task sub_task_level_2;
  
  struct rdabt_sdp_primitive_task* p_next;
};


void rdabt_sdp_add_primitive_task(struct rdabt_sdp_primitive_task *p_task);
void rdabt_sdp_free_primitive_task(struct rdabt_sdp_primitive_task *pTask);

//#if SDP_SDAP  //SDP_SDAP include many mgr functions, we just need three, changed by xzc
void rdabt_sdp_w4_connections(struct rdabt_sdp_primitive_task* pTask,u_int32 length, u_int8* pData, u_int8* pContinue);
void rdabt_sdp_find_services(struct rdabt_sdp_primitive_task* pTask,u_int8* pContinue);
//#endif /* SDP_SDAP */

void rdabt_sdp_w4_service(struct rdabt_sdp_primitive_task* pTask,u_int32 length, u_int8* pData, u_int8* pContinue);

//#if SDP_SDAP//SDP_SDAP include many mgr functions, we just need three, changed by xzc
void rdabt_sdp_search_attributes(struct rdabt_sdp_primitive_task* pTask,u_int8* pContinue);
//#endif /* SDP_SDAP */

void rdabt_sdp_w4_attributes(struct rdabt_sdp_primitive_task* pTask,u_int32 length, u_int8* pData, u_int8* pContinue);

#if SDP_SDAP

void rdabt_sdp_w4_enumerate(struct rdabt_sdp_primitive_task *pTask,u_int32 length, u_int8* pData, u_int8* pContinue);
#endif /* SDP_SDAP */
void rdabt_sdp_w4_browse_connections(struct rdabt_sdp_primitive_task* pTask,u_int32 length, u_int8* pData, u_int8* pContinue);

void rdabt_sdp_find_services_attributes(struct rdabt_sdp_primitive_task* pTask,u_int8* pContinue);

void rdabt_sdp_w4_service_attributes(struct rdabt_sdp_primitive_task* pTask,u_int32 length, u_int8* pData, u_int8* pContinue);


#if SDP_GENERIC_BROWSE

void rdabt_sdp_generic_browse(struct rdabt_sdp_primitive_task* pTask,u_int32 length, u_int8* pData, u_int8* pContinue);

#endif /* SDP_GENERIC_BROWSE */


void rdabt_sdp_timer_handler(void *pTask);


void rdabt_sdp_finish_primitive_task(struct rdabt_sdp_primitive_task *pTask);


void rdabt_sdp_int_ss(struct rdabt_sdp_primitive_task* pTask,u_int32 length, u_int8* pData, u_int8* pContinue);
void rdabt_sdp_int_find_services(struct rdabt_sdp_primitive_task* pTask,u_int8* pContinue);

void rdabt_sdp_int_sa(struct rdabt_sdp_primitive_task* pTask,u_int32 length, u_int8* pData, u_int8* pContinue);
void rdabt_sdp_int_search_attributes(struct rdabt_sdp_primitive_task* pTask,u_int8* pContinue);


void rdabt_sdp_int_ssa(struct rdabt_sdp_primitive_task* pTask,u_int32 length, u_int8* pData, u_int8* pContinue);
void rdabt_sdp_int_find_service_attributes(struct rdabt_sdp_primitive_task* pTask,u_int8* pContinue);

void rdabt_sdp_int_store_results(struct rdabt_sdp_primitive_task* pTask, u_int8* pContinue, u_int16 status, u_int8 type);


#endif /* SDP_STATE_MACHINE_H */



#endif /* SDP_CLIENT */

